package com.example.wxytest.demos.controller;

import com.example.wxytest.demos.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.wxytest.demos.Student;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {
    @Autowired
    StudentService studentService;

    @GetMapping("/all")
    public List<com.example.wxytest.demos.Student> findAll() {
        return studentService.findAll();
    }

    @GetMapping("/{id}")
    public com.example.wxytest.demos.Student findById(@PathVariable Integer id) {
        return studentService.findById(id);
    }

    @PostMapping
    public void add(@RequestBody Student student) {
        studentService.add(student);
    }

    @PutMapping
    public void update(@RequestBody Student student) {
        studentService.update(student);
    }

    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable Integer id) {
        studentService.deleteById(id);
    }
}